package sde.actor;

import java.util.HashMap;
import java.util.Map;


public class MessagesInformation {
	
	private static class Couple{
		double mean;
		int n;
	}
	
	private static final int MIN_N=5;
	
	private Map<Message, Couple> map = new HashMap<>();
	
	public boolean isAvailable(Message m){
		Couple c = map.get(m);
		if(c !=null && map.get(m).n >= MIN_N){
			return true;
		}
		return false;
	}
	
	public void start(Message m, double time){
		Couple c = map.get(m);
		if(c != null){
			c.mean=(c.mean+time)/c.n++;
		}else{
			c=new Couple();
			c.mean=time;
			c.n=1;
			map.put(m,c);
		}
	}
	
	public void stop(Message m, double time){
		
	}
	
	public double get(Message m){
		return map.get(m).mean;
	}
	
}
